package com.xyoto.takeawayBusiness.controller;

import com.xyoto.takeawayBusiness.aspect.annotation.RequiresLogin;
import com.xyoto.takeawayBusiness.dto.*;
import com.xyoto.takeawayBusiness.service.HomeService;
import com.xyoto.takeawayBusiness.service.ShopService;
import com.xyoto.takeawayBusiness.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/home")
@Api(tags = "首页模块")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @Autowired
    private ShopService shopService;

    @RequiresLogin
    @GetMapping("/getRefundOrderList")
    @ApiOperation("分页查询新订单，处理中，退款单订单列表")
    public Result getOrderListByOrderType(@Valid PageDTO pageDTO, @RequestParam("orderType") Integer orderType){
        return homeService.getOrderListByOrderType(pageDTO,orderType);
    }

    @RequiresLogin
    @GetMapping("/orderReceiving")
    @ApiOperation("接单打印")
    public Result orderReceiving(@NotNull(message = "订单id不能为空")
                    @RequestParam("id") String orderId){
        return homeService.orderReceiving(orderId);
    }

    @RequiresLogin
    @PostMapping("/updateShopInfo")
    @ApiOperation(value = "更新店铺", notes = "更新店铺信息")
    public Result updateShopInfo(UpdateShopInfoDto shopInfoDto){
        return shopService.updateShopInfo(shopInfoDto);
    }

    @RequiresLogin
    @PostMapping("/updateOrderStatus")
    @ApiOperation(value = "修改订单状态", notes = "修改订单状态值")
    public Result updateOrderStatus(@Valid @RequestBody UpdateOrderStatusDto updateDto){
        return shopService.updateOrderStatus(updateDto);
    }


    @RequiresLogin
    @PostMapping("/saveCategory")
    @ApiOperation("新增经营品类")
    public Result saveCategory(@Valid @RequestBody SaveCategoryDTO saveCategoryDTO){
        return homeService.saveCategory(saveCategoryDTO);
    }

    @RequiresLogin
    @GetMapping("/getAllCategory")
    @ApiOperation("获取经营品类列表")
    public Result getAllCategory(){
        return homeService.getAllCategory();
    }

    @RequiresLogin
    @PostMapping("/updateCategory")
    @ApiOperation("修改经营品类")
    public Result updateCategory(@Valid @RequestBody UpdateCategoryDTO updateCategoryDTO){
        return homeService.updateCategory(updateCategoryDTO);
    }

    @RequiresLogin
    @GetMapping("/getShopping")
    @ApiOperation(value = "获取商品详情", notes = "根据商品id获取商品详情信息")
    public Result getShopping(@NotNull(message = "商品id不能为空") @RequestParam("id") Integer id){
        return homeService.getShopping(id);
    }
}
